import 'package:flutter/material.dart';
import '/config/decoders.dart';
import 'package:nylo_framework/nylo_framework.dart';
import '/app/models/tenant.dart';

class TenantApiService extends NyApiService {
  TenantApiService({BuildContext? buildContext})
      : super(buildContext, decoders: modelDecoders);

  @override
  String get baseUrl => getEnv('API_BASE_URL');

  /// Return a list of Tenant
  Future<List<Tenant>?> fetchAll({dynamic query}) async {
    return await network<List<Tenant>>(
      request: (request) =>
          request.get("/endpoint-path", queryParameters: query),
    );
  }

  /// Find a Tenant
  Future<Tenant?> find({required int id}) async {
    return await network<Tenant>(
      request: (request) => request.get("/endpoint-path/$id"),
    );
  }

  /// Create a Tenant
  Future<Tenant?> create({required dynamic data}) async {
    return await network<Tenant>(
      request: (request) => request.post("/endpoint-path", data: data),
    );
  }

  /// Update a Tenant
  Future<Tenant?> update({dynamic query}) async {
    return await network<Tenant>(
      request: (request) =>
          request.put("/endpoint-path", queryParameters: query),
    );
  }

  /// Delete a Tenant
  Future<bool?> destroy({required int id}) async {
    return await network<bool>(
      request: (request) => request.delete("/endpoint-path/$id"),
    );
  }
}
